<?php
/**
 * Created by PhpStorm.
 * User: SATA
 * Date: 2017/10/6
 * Time: 14:42
 */

namespace app\admin\model;
use think\Model;

class Appointment extends Model
{
    protected $autoWriteTimestamp = "datetime";

    /**
     * 删除状态为-1的数据
     * @return true 删除成功 flase 删除失败
     */
    public function remove(){
        $res = $this->where(["status"=>-1])->delete();
        return $res;
    }

    /**
     * 列出所有预约
     * @param array $where 筛选条件
     * @param string $order 排列条件
     * @return array 订单列表
    */
    public function lists($where=array(),$order=''){
        $listRows = config('list_rows') > 0 ? config('list_rows') : 10;
        $test = new Home_member();
        $student = $test->field('id,username,email,mobile')->buildSql();
        $teacher = Model('Document')->field('id,name')->buildSql();
        $appointment = Model('Appointment')->alias('a')->join([$student=>'s'],'a.student_id=s.id')
            ->join([$teacher=>'t'],'a.teacher_id=t.id')->where($where)->paginate($listRows);
        return $appointment;
    }

}